    function Marker(item)
    {
        this.onGotImages = function(response)
        {
            var expected = '{\"ResultSet\":{';
            if (response.substring(0, expected.length) == expected)
            {
                var obj = eval('(' + response + ')');
                var results = obj.ResultSet.Result;
                mapGadget.thumbsLoaded = results.length;

                var dimension = Math.floor(Math.sqrt(mapGadget.thumbCount));
                var imgSize = Math.floor((mapGadget.paneWidth - 1 * dimension) / dimension) - 2;
                var table = '<span></span><table style="width:' + mapGadget.paneWidth + 'px;" cellspacing ="1" cellpadding="0">';
                for (var i = 0; i < results.length; i += dimension)
                {
                    table += mapGadget.getRow(results, i, i + dimension, imgSize);
                }
                table += '</table>';

                var thumbTable = _gel("thumbs" + mapGadget.id);
                if (thumbTable)
                {
                    thumbTable.innerHTML = table;
                }
            }
        };
    }

    var mapGadget =
    {
        prefs : new Object(),

        source :  "",
        stored_source :  "",

        map : new GMap2(_gel("map")),
        items : new Array(),

        paneWidth : 150,

        marker : new Object(),
        id : -1,

        cached : true,
        imageArray : new Array(),
        loadedImages : 0,

        thumbsLoaded : 0,
        thmubTable : "",
        thumbCount : 16,

        orkutResponse : "",

        imageFeed : "http://search.yahooapis.com/ImageSearchService/V1/imageSearch?appid=AyfZsPDV34E4NtYkfxBPYIz7GaiSP2rgJSZJMwRhUNnAT0vrPi.P08OJbXB1HzfgMg--",

        getUserPrefs : function()
        {
            mapGadget.source = mapGadget.prefs.getString("visitor_url");
            mapGadget.stored_source = mapGadget.prefs.getString("stored_visitor_url");

            var thumbCount = mapGadget.prefs.getInt("thumbGrid");
            mapGadget.thumbCount = thumbCount * thumbCount;

            //mapGadget.paneWidth = mapGadget.prefs.getInt("thumbGridWidth");
            mapGadget.paneWidth = 135;
            _IG_AdjustIFrameHeight();
        },

        getVisitorData : function()
        {
            var url = mapGadget.source;

            url = mapGadget.stored_source

            //store last location - otherwise permission denied : Window.setProperty
            GEvent.addListener(mapGadget.map, "moveend", function()
            {
                var center = mapGadget.map.getCenter();
                mapGadget.prefs.set("map_location", center.toUrlValue());
                mapGadget.prefs.set("map_zoom", mapGadget.map.getZoom());
            });

            url += "&output=js&type=visitors-list&limit=100";
            url = encodeURI(url);

            _IG_FetchContent(url, mapGadget.onGotVisitorData);

            mapGadget.doRequest(google.people.DataRequest.getFriendDataRequest(), mapGadget.onGotOrkutData);

        },


        doRequest : function(dataRequest, opt_callback)
        {
            dataRequest['MyAppName'] = 'Orkut Visitor Map';
            google.people.requestData(dataRequest, opt_callback);
        },


        onGotOrkutData : function(dataResponse)
        {
            mapGadget.orkutResponse = dataResponse;
            var v = mapGadget.orkutResponse.get('viewer');
            var o = mapGadget.orkutResponse.get('owner');

            var of = mapGadget.orkutResponse.get('ownerFriends');


            var html = '<h2>owner friends</h2>';
            of.each(function(friend)
            {
                html += mapGadget.per(friend) + '<br>';
            });
            //			   alert(html);
        },

        onGotVisitorData : function(response)
        {
            var data = new Object();

            if ((response == null) || (response == ""))
            {
                return;
            }

            eval("data = " + response + ";");

            if (data.length > 0)
            {
                //store response object
                mapGadget.data = data;

                //for each visitor
                for (var i = 0; i < data.length; i++)
                {
                    var item = data[i];
                    mapGadget.items[i] = data[i];

                    //I somtimes see a lat/long pair of (0,0) returned by Clicky. This check prevents it getting plotted
                    var nullLatLongCheck = parseFloat(item.latitude) + parseFloat(item.longitude);

                    if ((item) && (nullLatLongCheck != 0))
                    {
                        var locationString = item.geolocation;

                        var url = mapGadget.imageFeed + "&results=" + mapGadget.thumbCount;
                        url += "&output=json";
                        url += "&query=" + encodeURIComponent(locationString);

                        var date = new Date();
                        date.setTime(item.unixtime * 1000);

                        var clickyUrl = item.url_clicky;

                        var point = new GLatLng(item.latitude, item.longitude);
                        mapGadget.marker = mapGadget.createMarker(point, i, mapGadget.getLocationHTML(i, locationString, date, clickyUrl), mapGadget.getProfileHTML(), mapGadget.getFriendsHTML());
                        mapGadget.map.addOverlay(mapGadget.marker);
                    }
                }
            }
        },


        renderMap : function()
        {
            var mapZoom = mapGadget.prefs.getInt("map_zoom");
            var mapLocation = mapGadget.prefs.getString("map_location");

            var daylight = new daylightLayer();
            daylight.cityLights = true;
            daylight.addToMap(mapGadget.map);

            if (mapLocation == "")
            {
                mapLocation = new GLatLng(0, 0);
            }
            else
            {
                coords = mapLocation.split(",");
                mapLocation = new GLatLng(_trim(coords[0]), _trim(coords[1]));
            }

            var otherOpts =
            {
                buttonHTML: "<img src='http://visitormap.googlecode.com/svn/trunk/images/zoom-button.gif' />",
                buttonZoomingHTML: "<img src='http://visitormap.googlecode.com/svn/trunk/images/zoom-button-activated.gif' />",
                buttonStartingStyle: {width: '24px', height: '24px'}
            };

            mapGadget.map.setCenter(mapLocation, mapZoom, __UP_mapType__);
            mapGadget.map.addControl(new GSmallZoomControl());
            mapGadget.map.addControl(new DragZoomControl({}, otherOpts, {}), new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(10, 10)));
            mapGadget.map.addControl(new GMapTypeControl());

            mapGadget.map.enableDoubleClickZoom();
            mapGadget.map.enableContinuousZoom();

        },

        addPoint : function()
        {

        },

        createMarker : function(point, i, locationHTML, profileHTML, friendsHTML)
        {
            mapGadget.marker = locationHTML;
            var marker = new GMarker(point);

            // Show this marker's index in the info window when it is clicked
            GEvent.addListener(marker, "click", function()
            {
                var tabs = [];
                tabs.push(new GInfoWindowTab("Location", locationHTML));
                tabs.push(new GInfoWindowTab("Profile", profileHTML));
                tabs.push(new GInfoWindowTab("Friends", friendsHTML));

                marker.openInfoWindowTabsHtml(tabs);

                var container;
                container = _gel("miniMap" + i);

                var minimap = new GMap(container);
                minimap.setMapType(__UP_mapType__);
                minimap.enableDoubleClickZoom();
                minimap.enableContinuousZoom();
                minimap.setCenter(point, 11);
                minimap.setMapType(__UP_mapType__);

                var miniMapMarker = new GMarker(point);
                minimap.addOverlay(miniMapMarker);

                if (__UP_miniMapControls__ > 0)
                {
                    minimap.addControl(new GSmallZoomControl());
                }

                if (__UP_miniMapControls__ > 1)
                {
                    minimap.addControl(new GMapTypeControl());
                }

                if (mapGadget.thumbCount > 0)
                {
                    mapGadget.loadedImages = 0;
                    mapGadget.getThumbTable(mapGadget.items, i);
                }

            });

            return marker;
        },

        addImageSearch : function()
        {
            GEvent.addListener(mapGadget.map, "moveend", function()
            {
                var center = mapGadget.map.getCenter();
            });

        },

        getProfileHTML : function()
        {

            infoWindowWidth = mapGadget.paneWidth * 2;

            var marker = '<div id="infowindow" style="background-color:white; font-size:80%; width:' + infoWindowWidth + 'px;">';
            marker += '<div style="text-align:left; width:' + infoWindowWidth + 'px; padding-right:10px; ">';
            marker += '<b>xxxxxxxxxx\'s</b> profile';
            marker += '<br/>';
            marker += 'last updated on <b>01/01/07</b>';

            marker += '</div>';
            marker += '<div style="text-align:right;">';
            marker += '<table cellpadding="0" cellspacing="1" style="width:' + infoWindowWidth + 'px;">';
            marker += '<tr>';
            marker += '<td valign="middle">';
            marker += '<img width="100%" height="100%" alt="user picture" src="http://www.orkut.com/img/i_nophoto128.gif"/>';
            marker += '</td>';
            marker += '<td valign="middle">';
            marker += 'Display name: xxxxxx<br/>';
            marker += 'Birthday: xxxxxx<br/>';
            marker += 'Likes: xxxxxx<br/>';
            marker += 'Dislikes: xxxxxx<br/>';
            marker += '</td>';
            marker += '</tr>';
            marker += '</table>';
            marker += '</div>';
            marker += '</div>';

            return marker;
        },

        getFriendsHTML : function()
        {

            infoWindowWidth = mapGadget.paneWidth * 2;

            var marker = '<div id="infowindow" style="background-color:white; font-size:80%; width:' + infoWindowWidth + 'px;">';
            marker += '<div style="text-align:left; width:' + infoWindowWidth + 'px; padding-right:10px; ">';
            marker += '<b>xxxxxxxxxx\'s</b> profile';
            marker += '<br/>';
            marker += 'last updated on <b>01/01/07</b>';

            marker += '</div>';
            marker += '<div style="text-align:left;"><br/>';
            marker += '<a href="#">Jim Smith</a><br/>';
            marker += '<a href="#">John Doe</a><br/>';
            marker += '<a href="#">Jane Plain</a><br/>';
            marker += '<a href="#">Jacques Hitt</a><br/>';
            marker += '</div>';
            marker += '</div>';

            return marker;
        },

        getLocationHTML : function (i, locationString, date, clickyUrl)
        {
            var dateString = date.toUTCString();

            var pw = '100%';
            var infoWindowWidth = mapGadget.paneWidth;

            var thumbCell = '&nbsp';
            if (mapGadget.thumbCount > 0)
            {
                thumbCell = '<div class="wraptocenter"><span></span><div style="text-align:center; width: ' + mapGadget.paneWidth + 'px; height: ' + mapGadget.paneWidth + 'px;" id="thumbs' + i + '">Loading images...</div></div>';
                infoWindowWidth = infoWindowWidth * 2;
            }
            else
            {
                infoWindowWidth = 200;
            }

            var miniMapWidth = (mapGadget.thumbCount > 0) ? mapGadget.paneWidth : 200;


            var marker = '<div id="infowindow" style="background-color:white; font-size:80%; width:' + infoWindowWidth + 'px;">';
            marker += '<div style="text-align:left; width:' + infoWindowWidth + 'px; padding-right:10px; ">';
            marker += 'Somebody in <b>' + locationString + '</b> visited';
            marker += '<br/>';
            marker += 'on <b>' + dateString + '</b>';

            marker += '</div>';
            marker += '<div style="text-align:right;">';
            marker += '<table cellpadding="0" cellspacing="1" style="width:' + infoWindowWidth + 'px;">';
            marker += '<tr>';
            marker += '<td valign="middle">';
            marker += '<div style="width:' + mapGadget.paneWidth + 'px; text-align:center; overflow:hidden; height: ' + (mapGadget.paneWidth) + 'px;" id="miniMap' + i + '">&nbsp;</div>';
            marker += '</td>';
            marker += '<td valign="middle">';
            marker += thumbCell;
            marker += '</td>';
            marker += '</tr>';
            marker += '</table>';
            if (__UP_showMore__)
            {
                //marker +=           '<a target="_blank" href="'  + clickyUrl + '">View this session on Clicky...</a>';
            }
            marker += '</div>';

            marker += '</div>';

            return marker;
        },

        getImageThumb : function(results, i, size)
        {
            var result = results[i];

            if (_args()["mode"] == "canvas")
            {
                mapGadget.imageArray[i] = new Image();
                mapGadget.imageArray[i].src = (mapGadget.cached ? _IG_GetImageUrl(result.Url) : result.Url);
            }

            var thumb = '<a class="thumbnail" target="_top" href="' + result.Url + '">' +
                        '<span></span><img onload="mapGadget.checkLoaded()"' +
                        'class="thumb" src="' + (mapGadget.thumbCount > 1 ? result.Thumbnail.Url : result.Url) + '" width="' + size + '" height="' + size + '"' +
                        'title="' + result.Summary + '"/>';

            if (_args()["mode"] == "canvas")
            {
                thumb += '<span>';
                thumb += mapGadget.thumbCount > 1 ? '<img src="' + mapGadget.imageArray[i].src + '"/>' : '';
                thumb += '<span>';
            }
            thumb += '</a>';

            return thumb;
        },

        checkLoaded : function(e)
        {
            mapGadget.loadedImages++;
            if (mapGadget.loadedImages == mapGadget.thumbsLoaded)
            {
                //console.log("done");
            }
        },

        getCell : function(results, i, size)
        {
            var result = results[i];

            var cell = '<td style="display: table-cell; vertical-align: middle; width:' + size + 'px; height:' + size + 'px;">' +
                       '<div class="wraptocenter" style="height:' + size + '">' +
                       (result ? mapGadget.getImageThumb(results, i, size) : '&nbsp') +
                       '	</div>' +
                       '</td>';
            return cell;
        },

        getRow : function(results, start, limit, imgSize)
        {
            var row = '<tr>';
            for (var i = start; i < limit; i++)
            {
                row += mapGadget.getCell(results, i, imgSize);
            }
            row += '</tr>';
            return row;
        },

        getThumbTable : function (locationResults, i)
        {
            var locationResult = locationResults[i];
            var locationString = locationResult.geolocation;

            var url = mapGadget.imageFeed + "&results=" + mapGadget.thumbCount;
            url += "&output=json";
            url += "&query=" + encodeURIComponent(locationString);

            mapGadget.id = i

            _IG_FetchContent(url, new Marker(locationResult).onGotImages);


        },

        per : function(person)
        {
            return person.getDisplayName() + ' (' + person.getId() + ')';
        },

        main : function()
        {
            _gel("map").style.height = _args()["h"] + "px";

            if (GBrowserIsCompatible())
            {
                mapGadget.prefs = new _IG_Prefs(__MODULE_ID__);
                mapGadget.renderMap();
                mapGadget.getUserPrefs();

                //_gel("map").style.height = mapGadget.prefs.getInt("gadgetHeight");

                //mapGadget.addImageSearch();
                mapGadget.getVisitorData();
            }
            _IG_Analytics("UA-582167-19", "/");
        }
    };

    _IG_RegisterOnloadHandler(mapGadget.main());
      